package com.cby.olive.sample.dialog

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.DatePicker
import android.widget.TimePicker
import androidx.fragment.app.DialogFragment
import com.cby.olive.sample.R
import java.util.*


/**
 * Description:TimeSelectDialog: 时间选择弹窗
 *
 * @author chenbaoyang
 * @create 2023/7/10 09:30
 */
class TimeSelectDialog : DialogFragment() {

    var listener: TimePickerListener? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.dialog_time_select, container, false)
    }

    //@RequiresApi(Build.VERSION_CODES.O)
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        // 在Java代码中获取TimePicker实例并设置监听器
        val timePicker: TimePicker = view.findViewById(R.id.time_picker)
        val sureBtn: Button = view.findViewById(R.id.btn_sure)
        val calendar: Calendar = Calendar.getInstance()
        timePicker.setOnTimeChangedListener { view, hourOfDay, minute ->
            listener?.onTime("$hourOfDay:$minute:00")
        }
    }
}


interface TimePickerListener{
    fun onTime(time: String)
}